﻿using Reflexive.IO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Reflexive.IO.Examples
{

    public class StringConverter : TypeConverter, ITypeConverter<byte[],string>
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return true;
        }

        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            byte[] ev = (byte[])value;
            return System.Text.ASCIIEncoding.UTF8.GetString(ev);
        }


        public string Convert(byte[] source)
        {
            return (string)ConvertTo(source, typeof(string));
        }
    }
}
